package com.devtty.collabhr.ui;

import com.vaadin.data.Item;
import com.vaadin.data.util.HierarchicalContainer;
import com.vaadin.ui.Tree;
import com.vaadin.ui.VerticalLayout;

public class CompanyTreeLayout extends VerticalLayout {

	private static final String[][] CT = {
		{"Vertrieb", "Meier", "Mueller"},
		{"Projektmanagement", "Schulze", "Lehmann"}
	};
	
	public static final String SSS = "name";
	
	Tree tree = null;
	
	public CompanyTreeLayout(){
		tree = getTree();
		addComponent(tree);
	}
	
	private Tree getTree(){
		Tree t = new Tree();
		t.setContainerDataSource(getCompanyTree());
		t.setItemCaptionPropertyId(SSS);
		return t;
	}
	
	private HierarchicalContainer getCompanyTree(){
		Item item = null;
		int itemId = 0;
		
		HierarchicalContainer c = new HierarchicalContainer();
		c.addContainerProperty(SSS, String.class, null);
		
		for(int i=0; i<CT.length; i++){
			item = c.addItem(itemId);
			item.getItemProperty(SSS).setValue(CT[i][0]);
			c.setChildrenAllowed(itemId, true);
			itemId++;
			for(int j=1; j < CT[i].length; j++){
				item = c.addItem(itemId);
				item.getItemProperty(SSS).setValue(CT[i][j]);
				c.setParent(itemId, itemId - j);
				c.setChildrenAllowed(itemId, false);
				itemId++;
			}
		}
		
		return c;
	}
}
